﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KnowledgeCommunity.Model;
using KnowledgeCommunity.Service;
using KnowledgeCommunity.Web.Models;
using KnowledgeCommunity.Web.DbHelper;

namespace KnowledgeCommunity.Web.Controllers
{
    public class CollegeController : Controller
    {
        CollegeHelper myCollegeHelper = new CollegeHelper();
        //
        // GET: /College/

        public ActionResult Index()
        {
            var College = myCollegeHelper.FindAll();
            ViewData["CollegeList"] = College;
            return View();
        }

        public ActionResult Details(int id)
        {
            var _College = myCollegeHelper.FindById(id);
            return View(_College);
        }

        public ActionResult Create()
        {
            return View();
        }

        public ActionResult Create(College model)
        {
            bool n = myCollegeHelper.Create(model);
            if (n)
                return Index();
            else
            {
                return RedirectToAction("Error", "Notice", new { type = 1 });
            }
        }

        public ActionResult Edit(int id)
        {
            var _College = myCollegeHelper.FindById(id);
            return View(_College);
        }

        public ActionResult Edit(College model)
        {

            return View();
        }

        public ActionResult Delete(int id)
        {
            var _College = myCollegeHelper.FindById(id);
            return View(_College);
        }

        public ActionResult Delete(int id, FormCollection collection)
        {
            bool n = myCollegeHelper.Delete(id);
            if (n)
                return Index();
            else
                return RedirectToAction("Error", "Notice", new { type = 2 });
        }

    }
}
